package net.sf.nlp.ltag.parser.earley;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class EarleyStateSet
{
	private List<EarleyState> states = new ArrayList<EarleyState>();
	private ConcurrentLinkedQueue<EarleyState> stateQueue;
	
	public EarleyStateSet(ConcurrentLinkedQueue<EarleyState> stateQueue)
	{
		this.stateQueue = stateQueue;
	}
	
	public List<EarleyState> getStates() {
		return states;
	}

	public synchronized void addLTAGState(EarleyState state)
	{
		states.add(state);
		
		if (stateQueue != null)
			stateQueue.offer(state);
	}
	
	public void setStates(List<EarleyState> states) {
		this.states = states;
	}

	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		
		sb.append("[");
		for (EarleyState state : states)
			sb.append(state.toString()).append(", ");
		
		if (states.size() > 0)
			sb.delete(sb.length() - 2, sb.length());
		
		sb.append("]");
		
		return sb.toString();
	}
	
	/*
	public LTAGStateSet clone()
	{
		LTAGStateSet clone = null;
		
		try 
		{
			clone = (LTAGStateSet)super.clone();
			List<LTAGState> cloneStates = new ArrayList<LTAGState>();
			
			for (LTAGState state : states)
				cloneStates.add(state.clone());
			
			clone.setStates(cloneStates);
		} 
		catch (CloneNotSupportedException e) 
		{
			e.printStackTrace();
		}
		
		return clone;
	}*/
}
